package day15.udpsocket02;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Xiao
 * @date 2021/8/9
 */
public class Server06 {
    /**
     * 6. 使用TCP完成文件上传。
     */
    public static void main(String[] args) throws IOException {
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                3,
                5,
                2,
                TimeUnit.MINUTES,
                new ArrayBlockingQueue<>(4),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        //创建ServerSocket对象，建立连接
        ServerSocket ss = new ServerSocket(12121);
        //循环改进
        while (true) {
            //调用accept()方法，监视客户端
            Socket so = ss.accept();
            ServerThread st = new ServerThread(so);
            //多线程改进
//            new Thread(st).start();
            //线程池改进
            pool.submit(st);
        }
//        ss.close();
    }
}
